package com.szgr.baoyin.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.szgr.baoyin.R;
import com.szgr.baoyin.model.CardMessage;
import com.szgr.baoyin.utils.ViewFindUtils;

import java.util.List;

/**
 * Created by yang on 15/12/11.
 */
public class CardMessageListAdapter extends BaseAdapter {
    private Context mContext;
    private List<CardMessage> data;
    private View.OnClickListener listener;
    public CardMessageListAdapter(Context context, List<CardMessage> data,View.OnClickListener listener){
        mContext = context;
        this.data = data;
        this.listener = listener;
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_card_message_list_view,parent,false);
        }

        TextView tv_name = ViewFindUtils.hold(convertView,R.id.protect_address_company);
        TextView tv_card = ViewFindUtils.hold(convertView,R.id.protect_address_faren);
        TextView tv_phone = ViewFindUtils.hold(convertView,R.id.protect_address_faren_phone);
        TextView tv_company= ViewFindUtils.hold(convertView,R.id.protect_address_shengchan);
        TextView tv_companyAddress = ViewFindUtils.hold(convertView,R.id.protect_address_shengchan_phone);
        TextView tv_emailAddress = ViewFindUtils.hold(convertView,R.id.protect_address_address);
        TextView tv_email = ViewFindUtils.hold(convertView,R.id.protect_address_addresss);
        ImageView img_delete = ViewFindUtils.hold(convertView,R.id.item_delete);

        CardMessage cardMessage = data.get(position);
        tv_name.setText(cardMessage.getEnterprise_author());
        tv_card.setText(cardMessage.getEnterprise_author_idcard());
        tv_phone.setText(cardMessage.getEnterprise_phone());
        tv_company.setText(cardMessage.getEnterprise_name());
        tv_companyAddress.setText(cardMessage.getEnterprise_address());
        tv_emailAddress.setText(cardMessage.getEnterprise_address_recv());
        tv_email.setText(cardMessage.getEnterprise_email());
        img_delete.setTag(position);
        img_delete.setOnClickListener(listener);

        return convertView;
    }

    public void setData(List<CardMessage> data) {
        this.data = data;
        notifyDataSetChanged();
    }
}
